//判断是否登录
let username=JSON.parse(sessionStorage.getItem('user'))
function isLogin(){
    if(username==null){
        location.href='../login.html'
    }
}

//管理员头像显示
function yonghu(){
    if(username.juese!=undefined){
        $('#yonghu').append(`
        <div>
            <img src="${username.src}">
        </div>
        <span>${username.juese}</span>
        <span onclick='tuichu()' data-toggle="modal" data-target="#myModal">退出登录</span>
        `)
        return
    }
    $('#yonghu').append(`
    <img src="${username.src}">
    <span onclick='tuichu()' data-toggle="modal" data-target="#myModal">退出登录</span>
    `)
}

//退出登录
function tuichu(){
    $('.shouhang').append(`
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" id='title'>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">提示</h4>
                </div>
                <div class="modal-body" id='item'>
                    <h4>是否确定退出登录？</h4>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id='queding'>确定</button>
                </div>
            </div>
        </div>
    </div>
    `)
    $('#title').css({
        textAlign:'center',
        color:'black'
    })
    $('#item').css({
        color:'black'
    })
    $('.shouhang').on('click','#queding',function(){
        sessionStorage.clear()
        location.href='../login.html'
    })
}

//判断是否具有打开该页面的权限
function glqx(str){
    if(JSON.parse(getData('user')).guanli!=undefined){
        for(let i=0;i<JSON.parse(getData('user')).guanli.length;i++){
            if(JSON.parse(getData('user')).guanli[i].name==str){
                return JSON.parse(getData('user')).guanli[i]
            }
        }
        alert('你没有打开该页面的权限')
        history.go(-1)
        return
    }
    alert('你没有打开该页面的权限')
    history.go(-1)
}


//判断是否有执行该操作的权限
function czqx(data,content){
    if(data.quanxian.length!=undefined){
        for(let i=0;i<data.quanxian.length;i++){
            if(data.quanxian[i].name==content){
                return 
            }
        }
        alert('你没有执行该操作的权限')
        return true
    }
    alert('你没有执行该操作的权限')
    return true
}